package org.yatr.ttcn.rt.impl;

import java.util.HashMap;
import java.util.Map;

import org.etsi.ttcn.tri.TriComponentId;
import org.etsi.ttcn.tri.TriPortIdList;
import org.yatr.util.Util;

public class TriComponentIdImpl implements TriComponentId {
	private static final long serialVersionUID = 7407202781057773433L;
	String componentTypeName;
	String componentId;
	TriPortIdList portList;
	
	private TriComponentIdImpl(){}
	
	public TriComponentIdImpl(String moduleName, String componentTypeName){
		this.componentId = moduleName+"."+componentTypeName+"."+Util.getRandomString(10);
		this.componentTypeName = componentTypeName;
	}
	
	public boolean equals(Object o){
		return equals((TriComponentId)o);
	}

	public boolean equals(TriComponentId component) {
		return this.componentId.equals(component.getComponentId());
	}
	
	public int hashCode() {
		return componentId.hashCode();
	}

	public String getComponentId() {
		return componentId;
	}

	public String getComponentName() {
		return componentId;
	}

	public String getComponentTypeName() {
		return componentTypeName;
	}

	public TriPortIdList getPortList() {
		return portList;
	}
	
	public String toString(){
		return "[ComponentId: "+componentId+"]";
	}
	
	
	private static void test(){
		Map<TriComponentId, String> a = new HashMap<TriComponentId, String>();
		a.put(TypeFactory.newTriComponentId("Module1", "MyComponent"), "hihi");
		TriComponentId id = TypeFactory.newTriComponentId("Module1", "MyComponent");
		a.put(id, "hoho");
		
		System.out.println(id);
		System.out.println(a.containsKey(id));
		
	}
	public static void main(String[] args){
		test();
	}

}
